package com.hackerrank.challenges.sherlockandthebeast;

import java.util.Scanner;

public class Solution {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int T = in.nextInt();
		for(int t = 0; t < T; t++) {
			int N = in.nextInt(), n5 = 0;
			switch(N % 3) {
			case 0:
				n5 = N;
				break;
			case 1:
				n5 = 3 * (N / 3 - 3);
				break;
			case 2:
				n5 = 3 * (N / 3 - 1);
			}
			if(n5 < 0)
				System.out.println(-1);
			else {
				StringBuilder s = new StringBuilder();
				for(int i = 0; i < n5; i++)
					s.append(5);
				int n3 = N - n5;
				for(int i = 0; i < n3; i++)
					s.append(3);
				System.out.println(s);
			}
		}
	}
}
